﻿Imports System.Diagnostics
Imports System.Threading.Tasks
Module Funktionen

    ' _______ _________                  ______           __       _______ 
    '(  ____ \\__   __/       |\     /| (  ___ \         /  \     (  __   )
    '| (    \/   ) (          | )   ( | | (   ) )        \/) )    | (  )  |
    '| (__       | |          | |   | | | (__/ /           | |    | | /   |
    '|  __)      | |          ( (   ) ) |  __ (            | |    | (/ /) |
    '| (         | |           \ \_/ /  | (  \ \           | |    |   / | |
    '| (____/\   | |            \   /   | )___) )        __) (_ _ |  (__) |
    '(_______/   )_(    _____    \_/    |/ \___/  _____  \____/(_)(_______)
    '                  (_____)                   (_____)             
    Public Sub placeholder1()



    End Sub
    '   ##                                                                                                ##  
    '  ##    ____   ___   ____  ___  ___  ___  ______  ____ ____  __ __ __    ____  __ __ __  __   ___     ##  
    ' ##    ||     // \\  || \\ ||\\//|| // \\ | || | ||    || \\ || // ||    || \\ || || ||\ ||  // \\     ##    
    ' ##    ||==  ((   )) ||_// || \/ || ||=||   ||   ||==  ||_// ||<<  ||    ||_// || || ||\\|| (( ___     ##  
    ' ##    ||     \\_//  || \\ ||    || || ||   ||   ||___ || \\ || \\ ||__| || \\ \\_// || \||  \\_||    ## 
    '  ##                                                                                                ## 

    '##################### - {Name} - ##################### > Kennzeichnet den Start eines Bereiches
    '#-#-#-#-#-#-#-#-#-#-# - {Name} - #-#-#-#-#-#-#-#-#-#-# > Kennzeichnet das Ende eines Bereiches
    '++++++++++++++++++ | {Name} | ++++++++++++++++++      > Kennzeichnet den Start einer Funktion
    '------------------ | {Name} | ------------------       > Kennzeichnet das Ende einer Funktion


    '##################### - START FUNKTIONSLISTE - #####################
    '  _____                   _      _     _                         _   _         _          
    ' |  ___|  _   _   _ __   | | __ | |_  (_)   ___    _ __    ___  | | (_)  ___  | |_    ___ 
    ' | |_    | | | | | '_ \  | |/ / | __| | |  / _ \  | '_ \  / __| | | | | / __| | __|  / _ \
    ' |  _|   | |_| | | | | | |   <  | |_  | | | (_) | | | | | \__ \ | | | | \__ \ | |_  |  __/
    ' |_|      \__,_| |_| |_| |_|\_\  \__| |_|  \___/  |_| |_| |___/ |_| |_| |___/  \__|  \___|
    ' Funktionsname                         Funktionsbeschreibung

    'nur_2_von_4_checkbox()                 Diese Funktion sorgt dafür, dass immer nur 2 Checkboxen ausgewählt sind und deaktiviert die die Steuererlemente die nicht aktiv sein dürfen.
    'Berechnung_Watt()                           Berechnet die Werte für die die Leistung
    '#-#-#-#-#-#-#-#-#-#-# - ENDE FUNKTIONSLISTE - #-#-#-#-#-#-#-#-#-#-#
    Public Sub placeholder()



    End Sub
    '##################### - Dimensioniere Variablen für Checkbox-Wert - #####################
    Dim var_bool_P As Boolean '
    Dim var_bool_U As Boolean '
    Dim var_bool_R As Boolean '
    Dim var_bool_I As Boolean '
    Dim var_Int_P As Integer '
    Dim var_Int_U As Integer '
    Dim var_Int_R As Integer '
    Dim var_Int_I As Integer '
    '#-#-#-#-#-#-#-#-#-#-# - Dimensioniere Variablen für Checkbox-Wert - #-#-#-#-#-#-#-#-#-#-#
    Public Sub nur_2_von_4_checkbox()
        '++++++++++++++++++ | Berechne die Anzahl der gecheckten Checkboxen  | ++++++++++++++++++
        Dim varP As Long = 1
        Dim varU As Long = 1
        Dim varR As Long = 1
        Dim varI As Long = 1
        Dim testP As Long = 1
        Dim testU As Long = 1
        Dim testR As Long = 1
        Dim testI As Long = 1
        If PURIv2.CheckBox_P.Checked Then
            varP = varP + 1
        Else
            varP = varP - 1
        End If
        If PURIv2.CheckBox_U.Checked Then
            varU = varU + 1
        Else
            varU = varU - 1
        End If
        If PURIv2.CheckBox_R.Checked Then
            varR = varR + 1
        Else
            varR = varR - 1
        End If
        If PURIv2.CheckBox_I.Checked Then
            varI = varI + 1
        Else
            varI = varI - 1
        End If
        '------------------ | Berechne die Anzahl der gecheckten Checkboxen  | ------------------
        '++++++++++++++++++ | Checkbox 4 (P) | ++++++++++++++++++
        testP = varU + varR + varI
        If testP < 4 Then
            PURIv2.CheckBox_P.Enabled = True
            PURIv2.TextBox_P.ReadOnly = False
            If PURIv2.CheckBox_P.Checked Then
                PURIv2.TextBox_P.Enabled = True
                PURIv2.TextBox_P.Text = "1"
                PURIv2.TrackBar_P.Enabled = True
                PURIv2.NumUpDown_P.Enabled = True
            Else
                PURIv2.TextBox_P.Text = "0"
                PURIv2.TrackBar_P.Enabled = False
                PURIv2.NumUpDown_P.Enabled = False
                PURIv2.TextBox_P.Enabled = False
            End If
        Else
            PURIv2.CheckBox_P.Enabled = False
            PURIv2.TextBox_P.ReadOnly = True
        End If
        '------------------ | Checkbox 4 (P) | ------------------
        '++++++++++++++++++ | Checkbox 3 (U) | ++++++++++++++++++
        testU = varP + varR + varI
        If testU < 4 Then
            PURIv2.CheckBox_U.Enabled = True
            PURIv2.TextBox_U.ReadOnly = False
            If PURIv2.CheckBox_U.Checked Then
                PURIv2.TextBox_U.Text = "1"
                PURIv2.TrackBar_U.Enabled = True
                PURIv2.NumUpDown_U.Enabled = True
                PURIv2.TextBox_U.Enabled = True
            Else
                PURIv2.TextBox_U.Text = "0"
                PURIv2.TrackBar_U.Enabled = False
                PURIv2.NumUpDown_U.Enabled = False
                PURIv2.TextBox_U.Enabled = False
            End If
        Else
            PURIv2.CheckBox_U.Enabled = False
            PURIv2.TextBox_U.ReadOnly = True
        End If
        '------------------ | Checkbox 3 (U) | ------------------
        '++++++++++++++++++ | Checkbox 2 (R) | ++++++++++++++++++
        testR = varP + varU + varI
        If testR < 4 Then
            PURIv2.CheckBox_R.Enabled = True
            PURIv2.TextBox_R.ReadOnly = False
            If PURIv2.CheckBox_R.Checked Then
                PURIv2.TextBox_R.Text = "1"
                PURIv2.TrackBar_R.Enabled = True
                PURIv2.NumUpDown_R.Enabled = True
                PURIv2.TextBox_R.Enabled = True
            Else
                PURIv2.TextBox_R.Text = "0"
                PURIv2.TrackBar_R.Enabled = False
                PURIv2.NumUpDown_R.Enabled = False
                PURIv2.TextBox_R.Enabled = False
            End If
        Else
            PURIv2.CheckBox_R.Enabled = False
            PURIv2.TextBox_R.ReadOnly = True
        End If
        '------------------ | Checkbox 2 (R) | ------------------
        '++++++++++++++++++ | Checkbox 1 (I) | ++++++++++++++++++
        testI = varP + varU + varR
        If testI < 4 Then
            PURIv2.CheckBox_I.Enabled = True
            PURIv2.TextBox_I.ReadOnly = False
            If PURIv2.CheckBox_I.Checked Then
                PURIv2.TextBox_I.Text = "1"
                PURIv2.TrackBar_I.Enabled = True
                PURIv2.NumUpDown_I.Enabled = True
                PURIv2.TextBox_I.Enabled = True
            Else
                PURIv2.TextBox_I.Text = "0"
                PURIv2.TrackBar_I.Enabled = False
                PURIv2.NumUpDown_I.Enabled = False
                PURIv2.TextBox_I.Enabled = False
            End If
        Else
            PURIv2.CheckBox_I.Enabled = False
            PURIv2.TextBox_I.ReadOnly = True
        End If
        '------------------ | Checkbox 1 (I) | ------------------
    End Sub
    Public Sub Berechnung()

        Dim P As Long
        Dim U As Long
        Dim R As Long
        Dim I As Long

        Dim var_P As Long = CInt(Val(PURIv2.TextBox_P.Text))
        Dim var_U As Long = CInt(Val(PURIv2.TextBox_U.Text))
        Dim var_R As Long = CInt(Val(PURIv2.TextBox_R.Text))
        Dim var_I As Long = CInt(Val(PURIv2.TextBox_I.Text))

        Dim num_P As Long = CInt(Val(PURIv2.NumUpDown_P.Value))
        Dim num_U As Long = CInt(Val(PURIv2.NumUpDown_U.Value))
        Dim num_R As Long = CInt(Val(PURIv2.NumUpDown_R.Value))
        Dim num_I As Long = CInt(Val(PURIv2.NumUpDown_I.Value))

        Dim var_num_P As Long = (10 ^ num_P)
        Dim var_num_U As Long = (10 ^ num_U)
        Dim var_num_R As Long = (10 ^ num_R)
        Dim var_num_I As Long = (10 ^ num_I)

        P = var_P * (10 ^ num_P)
        U = var_U * (10 ^ num_U)
        R = var_R * (10 ^ num_R)
        I = var_I * (10 ^ num_I)

        P = Watt(U, R, I)
        U = Volt(P, R, I)
        R = Ohm(P, U, I)
        I = Ampere(P, U, R)

        PURIv2.num_P.Text = num_P
        PURIv2.num_U.Text = num_U
        PURIv2.num_R.Text = num_R
        PURIv2.num_I.Text = num_I


        PURIv2.var_P.Text = P
        PURIv2.var_U.Text = U
        PURIv2.Var_R.Text = R
        PURIv2.Var_I.Text = I

        PURIv2.var_num_P.Text = var_num_P
        PURIv2.var_num_U.Text = var_num_U
        PURIv2.var_num_R.Text = var_num_R
        PURIv2.var_num_I.Text = var_num_I

        PURIv2.string_ergebnis_P.Text = P & " " & PURIv2.Label_Einheit_P.Text

        PURIv2.string_ergebnis_U.Text = U & " " & PURIv2.Label_Einheit_U.Text

        PURIv2.string_ergebnis_R.Text = R & " " & PURIv2.Label_Einheit_R.Text

        PURIv2.string_ergebnis_I.Text = I & " " & PURIv2.Label_Einheit_I.Text

    End Sub

    Public Sub Case_NumUpDown_P()
        Select Case PURIv2.NumUpDown_P.Text 'sc-potenzen
            Case -9
                PURIv2.Label_Einheit_P.Text = "nW" '-9
            Case -8 To -6
                PURIv2.Label_Einheit_P.Text = "µW" '-8- -6
            Case -3 To -5
                PURIv2.Label_Einheit_P.Text = "mW" '-5- -3
            Case -2
                PURIv2.Label_Einheit_P.Text = "cW" '-2
            Case -1
                PURIv2.Label_Einheit_P.Text = "dW" '-1
            Case 0 To 2
                PURIv2.Label_Einheit_P.Text = "W" '0-2
            Case 3 To 5
                PURIv2.Label_Einheit_P.Text = "kW" '3-5
            Case 6 To 8
                PURIv2.Label_Einheit_P.Text = "MW" '6-8
            Case 9
                PURIv2.Label_Einheit_P.Text = "GW" '9
            Case Else
                'InfoCode
        End Select
    End Sub

    Public Sub Case_NumUpDown_U()
        Select Case PURIv2.NumUpDown_U.Text
            Case -1
                PURIv2.Label_Einheit_U.Text = "dV"
            Case -2
                PURIv2.Label_Einheit_U.Text = "cV"
            Case -3 To -5
                PURIv2.Label_Einheit_U.Text = "mV"
            Case -6 To -8
                PURIv2.Label_Einheit_U.Text = "µV"
            Case -9
                PURIv2.Label_Einheit_U.Text = "nV"
            Case 0 To 2
                PURIv2.Label_Einheit_U.Text = "V"
            Case 3 To 5
                PURIv2.Label_Einheit_U.Text = "kV"
            Case 6 To 8
                PURIv2.Label_Einheit_U.Text = "MV"
            Case 9
                PURIv2.Label_Einheit_U.Text = "GV"
            Case Else
                'InfoCode
        End Select
    End Sub

    Public Sub Case_NumUpDown_R()
        Select Case PURIv2.NumUpDown_R.Text
            Case -1
                PURIv2.Label_Einheit_R.Text = "dO"
            Case -2
                PURIv2.Label_Einheit_R.Text = "cO"
            Case -3 To -5
                PURIv2.Label_Einheit_R.Text = "mO"
            Case -6 To -8
                PURIv2.Label_Einheit_R.Text = "µO"
            Case -9
                PURIv2.Label_Einheit_R.Text = "nO"
            Case 0 To 2
                PURIv2.Label_Einheit_R.Text = "O"
            Case 3 To 5
                PURIv2.Label_Einheit_R.Text = "kO"
            Case 6 To 8
                PURIv2.Label_Einheit_R.Text = "MO"
            Case 9
                PURIv2.Label_Einheit_R.Text = "GO"
            Case Else
                'InfoCode
        End Select
    End Sub

    Public Sub Case_NumUpDown_I()
        Select Case PURIv2.NumUpDown_I.Text
            Case -1
                PURIv2.Label_Einheit_I.Text = "dA"
            Case -2
                PURIv2.Label_Einheit_I.Text = "cA"
            Case -3 To -5
                PURIv2.Label_Einheit_I.Text = "mA"
            Case -6 To -8
                PURIv2.Label_Einheit_I.Text = "µA"
            Case -9
                PURIv2.Label_Einheit_I.Text = "nA"
            Case 0 To 2
                PURIv2.Label_Einheit_I.Text = "A"
            Case 3 To 5
                PURIv2.Label_Einheit_I.Text = "kA"
            Case 6 To 8
                PURIv2.Label_Einheit_I.Text = "MA"
            Case 9
                PURIv2.Label_Einheit_I.Text = "GA"
            Case Else
                'InfoCode
        End Select
    End Sub
End Module
